<template>
  <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
            :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
            :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
            :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
    <!--表单开始-->

    <a-form ref="formRef" :model="formState" layout="vertical" :rules="RULES">
      <a-row :gutter="[12,12]">


        <a-col :span="12">
          <a-form-item label="场地代码" field="code">
            <a-input v-model="formState.code" placeholder="请填写场地代码"/>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="场地备注" field="name">
            <a-input v-model="formState.describe" placeholder="请填写场地备注"/>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="场地名称" field="name">
            <a-input v-model="formState.name" placeholder="请填写场地名称"/>
          </a-form-item>
        </a-col>

        <a-col :span="12">
          <a-form-item label="场地状态" field="status">
            <smart-dict v-model="formState.status" :url="DictOptions.PlaceStatus" placeholder="请选着场地状态"/>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="场地地址" field="address">
            <smart-addr v-model="formState.address" placeholder="请选着场地地址"/>
          </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item :label="`显示排序值 [ ${formState.sort} ]` " field="sort" tooltip="升序排序 显示值越小 显示越靠前">
            <a-slider v-model="formState.sort"/>
          </a-form-item>
        </a-col>

      </a-row>


    </a-form>
    <!--表单结束-->
  </a-drawer>
</template>

<script lang="ts" setup>


import {EditDrawer} from '@/libs/core'
import {DictOptions} from '@/libs/options'
import {PLACE_EDIT} from "../../resource/form";
import {ProductHttp} from '../../resource/http'


const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])
const {BODY, RULES} = PLACE_EDIT

const {addPlace, updatePlace} = ProductHttp
const config = {tplRecord: BODY, rawRecord: props.record, rowKey: 'id', emit}
const service = new EditDrawer(config).setAddRequest(addPlace).setUpdateRequest(updatePlace)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改档案' : '新增档案'


</script>
